//
//  NSBundle+JMIP.m
//  ImagePicker
//
//  Created by Jamin on 2018/10/16.
//  Copyright © 2018 jamin. All rights reserved.
//

#import "NSBundle+JMIP.h"

@implementation NSBundle (JMIP)


+ (instancetype)jmip_MainBundle {
    NSBundle *bundle = [NSBundle bundleForClass:NSClassFromString(@"JMImagePickerViewController")];
    
    return [NSBundle bundleWithPath:[bundle pathForResource:@"JMImagePickerViewController" ofType:@"bundle"]];
}

+ (NSString *)jmip_localizedStringForKey:(NSString *)key value:(NSString *)value {
    NSString *language = [NSLocale preferredLanguages].firstObject;
    if ([language hasPrefix:@"en"]) {
        language = @"en";
    } else if ([language hasPrefix:@"zh"]) {
        if ([language rangeOfString:@"Hans"].location != NSNotFound) {
            language = @"zh_CN"; // 简体中文
        } else { // zh-Hant\zh-HK\zh-TW
            language = @"zh_HK"; // 繁體中文
        }
    } else {
        language = @"en";
    }
    NSBundle *bundle = [NSBundle bundleWithPath:[[NSBundle jmip_MainBundle] pathForResource:language ofType:@"lproj"]];
    NSString *string = [bundle localizedStringForKey:key value:value table:nil];
    return string;
}


@end
